import { defineStore } from "pinia";

const useHomeStore = defineStore("homeStore", {
  state: () => {
    return {
      title: "陕西工业职业技术大学",
      // 当前选中的tab栏
      selectIndex: 0,
      // 导航栏高度
      navHeight: 0,
      // 导航栏距顶部距离
      navTop: 0,
      // 胶囊的高度
      navObj: null,
      // 胶囊宽度+距右距离
      navObjWid: null,
      // 控制局部企业内容显示隐藏
      checkShowV: false,
    };
  },
  actions: {
    updateTabbarIndex(index) {
      this.selectIndex = index;
    },
    // 更行菜单导航有关信息
    async updateMenuInfo() {
      let menuButtonObject = wx.getMenuButtonBoundingClientRect();

      wx.getSystemInfo({
        success: (res) => {
          //导航高度
          let statusBarHeight_ = res.statusBarHeight;
          let navTop_ = menuButtonObject.top;
          let navObjWid_ =
            res.windowWidth - menuButtonObject.right + menuButtonObject.width; // 胶囊按钮与右侧的距离 = windowWidth - right+胶囊宽度
          let navHeight_ =
            statusBarHeight_ +
            menuButtonObject.height +
            (menuButtonObject.top - statusBarHeight_) * 2;

          this.navHeight = navHeight_; //导航栏总体高度
          this.navTop = navTop_; //胶囊距离顶部距离
          this.navObj = menuButtonObject.height; //胶囊高度
          this.navObjWid = navObjWid_; //胶囊宽度(包括右边距离)

          console.log("navHeight：", this.navHeight);
        },
        fail(err) {
          console.log(err);
        },
      });
    },
    updateCheckShowV(data) {
      this.checkShowV = data;
    },
  },
  getters: {},
});

export default useHomeStore;
